﻿#region  Copyright (C) 2013 Unisys Corporation

// =============================================================================================
// All Rights Reserved. This work contains trade secrets and confidential material of UNISYS, 
// and its use or disclosure in whole or in part without explicit written permission of 
// UNISYS is prohibited. 
//  
// Product Name          :  Unisys e-Workflow and Imaging
// File Name             :  Deserializer.cs
// Authored By           :  Unisys Corporation
// =============================================================================================
//	Modified by                         Date            Version
// =============================================================================================
//	ronald.aguilar@cr.unisys.com      Jun 06, 2013    Initial Version
// =============================================================================================

#endregion

#region Using Region
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

#endregion

namespace Unisys.DuplicateCheck.Entity.Helper
{

    /// <summary>
    /// XML Deserializing class.
    /// </summary>
    public static class Deserializer
    {
        /// <summary>
        /// Deserialize XML content into specified object.
        /// </summary>
        /// <typeparam name="T">Class of returning object.</typeparam>
        /// <param name="xmlContent">XML content.</param>
        /// <returns></returns>
        public static T Deserialize<T>(string xmlContent) where T : class, new()
        {
            var xDoc = new XmlDocument();
            xDoc.Load(xmlContent);
            var objInstanciado = new T();
            TextReader varTxtLectura = new StringReader(xDoc.OuterXml);
            var varDeserializador = new XmlSerializer(objInstanciado.GetType());
            objInstanciado = (T)varDeserializador.Deserialize(varTxtLectura);
            varTxtLectura.Close();
            return objInstanciado;
        }
    }
}
